<?php

class Public_Post_EditInputView extends BlogPublicBaseView
{
	public function executeHtml(AgaviRequestDataHolder $rd)
	{
		$this->setupHtml($rd, 'blog');
		$params = $rd->getParameters();
		$ro = $this->getContext()->getRouting();
        /* @var $model Public_PostsModel */
		$model = $this->getContext()->getModel('Posts', 'Public');
        
        $post = $model->getPost($params['post_id']);
		
        $tags = array();
        foreach ($post->Tags as $tag) {
            $tags[] = $tag->tag;
        }
        $form_params = array(
            'post_id' => $post->id,
            'subject' => MarkupProcessor::getPostTitleHtml($post),
            'tags' => implode(',', $tags),
            'body' => $post->Body->body,
            //'post_shortcut' => $post->getShortcut(),
        );
        if ($post->is_commenting_enabled) {
            $form_params['comments_allowed'] = 1;
        }
        if ($post->is_published) {
            $form_params['published'] = 1;
        }
        
        $route_elements = array('post_id'=>$post->id);
        $this->setAttribute('submit_route', $ro->gen('post_by_id.edit', $route_elements));
        $this->setAttribute('post_shortcut', $post->shortcut);
        
        $this->getContext()->getRequest()->setAttribute('populate',
            new AgaviParameterHolder($form_params),
            'org.agavi.filter.FormPopulationFilter');
	}
}

?>
